package com.sharp.socket.io.controller;

import com.sharp.kernel.config.response.Response;
import com.sharp.kernel.config.response.ResponseHandler;
import com.sharp.kernel.vo.common.CommonResVO;
import com.sharp.kernel.vo.query.QueryRespVO;
import com.sharp.socket.io.bo.ChatMessage;
import com.sharp.socket.io.service.chat.ChatMessageHistoryService;
import com.sharp.socket.io.service.chat.ChatService;
import com.sharp.socket.io.vo.chat.history.ChatDeliveredReq;
import com.sharp.socket.io.vo.chat.history.ChatHistoryReq;
import com.sharp.socket.io.vo.chat.msg.ChatReq;
import com.sharp.socket.io.vo.chat.msg.ChatRes;
import com.sharp.socket.io.vo.chat.msg.RetractChatReq;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.List;

/**
 * Title: BaseChatController
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2020/9/8 17:11
 * @description Project Name: customer-robot
 * @Package: com.bhfae.customer.robot.controller
 */

public class BaseChatController {

    @Resource
    private ChatService chatService;
    @Resource
    private ChatMessageHistoryService chatMessageHistoryService;


    @ApiOperation(value = "发消息", notes = "发消息")
    @RequestMapping(value = "/chat", method = RequestMethod.POST)
    public ResponseEntity<Response<ChatRes>> chat(@RequestBody ChatReq req) {
        ChatRes res = chatService.chat(req);
        return ResponseHandler.generateResponse(res);
    }

    @ApiOperation(value = "撤回消息", notes = "撤回消息")
    @RequestMapping(value = "/chat/retract", method = RequestMethod.POST)
    public ResponseEntity<Response<CommonResVO>> retract(@RequestBody RetractChatReq req) {
        chatService.retract(req);
        return ResponseHandler.commonResponse();
    }

    @ApiOperation(value = "历史记录", notes = "获取历史记录")
    @RequestMapping(value = "/chat/history", method = RequestMethod.POST)
    public ResponseEntity<Response<QueryRespVO<ChatMessage>>> history(@RequestBody ChatHistoryReq req) {
        QueryRespVO<ChatMessage> res = chatMessageHistoryService.queryHistory(req);
        return ResponseHandler.generateResponse(res);
    }

    @ApiOperation(value = "获取未读记录", notes = "获取未读记录")
    @RequestMapping(value = "/chat/history", method = RequestMethod.GET)
    public ResponseEntity<Response<List<ChatMessage>>> unDeliver(ChatDeliveredReq req) {
        List<ChatMessage> res = chatMessageHistoryService.getUnDeliveredChatMessage(req);
        return ResponseHandler.generateResponse(res);
    }
}
